package com.oocl.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DbUtil {

	private static final String url = "jdbc:oracle:thin:@zha-ita129-w7:1521:xe";
	private static final String username = "LIAV2";
	private static final String password = "LIAV2";
	private static final String driverClass = "oracle.jdbc.OracleDriver";// 可不写，jvm可以自动识别加载jar包查看是否有connect驱动

	public static Connection connect() {
		Connection con = null;
		try {
			con = DriverManager.getConnection(url, username, password);
			Class.forName(driverClass);// 多个数据库都有加载驱动的情况下，区别确认所使用的数据库类型
		} catch (SQLException e1) {
			e1.printStackTrace();
		}catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		return con;
	}

	public static void free(Connection con, PreparedStatement pst, ResultSet rs) {
			//执行关闭回收
		try {
			if (rs != null) {
				rs.close();
			}
			if (pst != null) {
				pst.close();
			}
			if (con != null) {
				con.close();
			}

		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
}
